SpatialAudioListenerThe point from which a SpatialAudioRenderer2D renders the scene. Every renderer has exactly one listener. All sources are attenuated, filtered and panned relative to this listener.
The rotation is optional. With the default rotation of 0 the listener faces up on the screen, so sources on the left and right of the screen are panned left and right.
For 3D scenes, use SpatialAudioListener3D.
const renderer = new SpatialAudioRenderer2D(audioDevice);
// Every renderer already has a listener:
renderer.listener.setPosition(player.x, player.y);
// Optional: rotate the listener, for example towards the mouse.
renderer.listener.lookAt(mouse.x, mouse.y);
new SpatialAudioListener(options?: Partial<SpatialAudioListenerOptions>): SpatialAudioListener;
You normally do not construct a listener yourself: the renderer creates one. Use renderer.setSpatialAudioListener() to replace it.
options?: Partial<SpatialAudioListenerOptions> - Initial position, rotation and y-axis direction.id: stringA unique id, automatically generated when constructing the listener. Should NOT be changed.
position: Vector2World position of the listener. Defaults to { x: 0, y: 0 }.
rotation: numberFacing direction in radians, clockwise. 0 means facing up on the screen. Defaults to 0.
yAxis: SpatialYAxisDirectionDirection of the y-axis on screen. Kept in sync with the renderer this listener belongs to. Defaults to "down". See SpatialYAxisDirection.
setPosition(x: number, y: number): SpatialAudioListenerSets the world position.
x: numbery: numberSpatialAudioListener - The same listener. Can be used to stack methods.translate(dx: number, dy: number): SpatialAudioListenerMoves the listener by the given amount.
dx: numberdy: numberSpatialAudioListener - The same listener.setRotation(rotation: number): SpatialAudioListenerSets the facing direction in radians, clockwise, where 0 faces up on the screen.
rotation: numberSpatialAudioListener - The same listener.lookAt(x: number, y: number): SpatialAudioListenerRotates the listener so it faces the given point. Does nothing when the point equals the listener position.
x: numbery: numberSpatialAudioListener - The same listener.toLocal(position: Vector2): Vector3Converts a world position into listener space: x = right, y = up (always 0 in 2D), z = forward.
position: Vector2get forward(): Vector2Unit vector of the facing direction, in world space.
get right(): Vector2Unit vector pointing to the right of the listener, in world space.
This class does not emit any events.